package br.com.fogas.utils;

import java.util.Date;

import org.apache.commons.lang3.StringUtils;

public class SAPUtility {
	
	public String convertDateForSAP(Date data) {
		return FogasUtility.data.getStringByDateAndFormat(data, "yyyyMMdd");
	}
	
	public String convertTimeForSAP(Date data) {
		return FogasUtility.data.getStringByDateAndFormat(data, "HHmmss");
	}
	
	public String convertIntegerForSAP_10Digits(Integer valor) {
        return StringUtility.leftPad(String.valueOf(valor), 10, "0"); //String.format("%010d", valor);
    }
	
	public String convertIntegerForSAP_3Digits(Integer valor) {
        return StringUtility.leftPad(String.valueOf(valor), 3, "0");
    }
	
	public String convertIntegerForSAP_6Digits(Integer valor) {
        return StringUtility.leftPad(String.valueOf(valor), 6, "0");
    }
	
	public String convertDecimalForSAP(double value) {
		String vlrAux = FogasUtility.string.currencyFormat(value);
		vlrAux = StringUtils.replace(vlrAux, "R$", "").trim();
		vlrAux = StringUtils.replace(vlrAux, ".", "").trim();
		vlrAux = StringUtils.replace(vlrAux, ",", "").trim();
		String vl1 = StringUtils.substring(vlrAux, 0, vlrAux.length() - 2);
		String vl2 = StringUtils.substring(vlrAux, vlrAux.length() - 2, vlrAux.length());
		return vl1+"."+vl2;
	}
	
	public String convertBooleanForSAP(boolean valor) {
        return valor ? "X" : "";
    }
}
